<%@page import="obs.ClassThatDoesStuff"%>
<%@page import="obs.UserData"%>
<%@page contentType="text/html" pageEncoding="windows-1252"%>
<%
if(session.getAttribute("key") == null) {
    // If no session key then create a user data object
    UserData data = new UserData();
    
    // Assign the values entered to this new object
    data.setGrade(request.getParameter("grade"));
    data.setEmail(request.getParameter("email"));
    data.setAge(request.getParameter("age"));
    
    // Randomise them!
    int NUM_PAIRS = 16;
    int NUM_POOLS = 4;
    
    ClassThatDoesStuff doer = new ClassThatDoesStuff();
    data.setPool(doer.randomiseToPool(NUM_POOLS));
    data.setPairings(doer.randomiseOrder(NUM_PAIRS));
    data.setResponses(new int[NUM_PAIRS]);
    data.setPairingId(0);
    
    // Force the user data object into the GAE database
    data.persist();
    
    // The bit we store in the session is the (new) key of the user data object
    session.setAttribute("key", data.getEncodedKey());
    
          }

else {
    // Should not be on this page really  
    %>You are already registered!<%
       }       
%>
 <jsp:forward page="study.jsp"/>
